"
I am a RBBrowserEnvironment on a set of Pragmas.
I containt all entities that define methods using this pragmas.
Example:
(RBBrowserEnvironment new) forPragmas:{ #primitive:}.
"
Class {
	#name : 'RBPragmaEnvironment',
	#superclass : 'RBBrowserEnvironmentWrapper',
	#instVars : [
		'keywords',
		'condition'
	],
	#category : 'Refactoring-Environment',
	#package : 'Refactoring-Environment'
}

{ #category : 'accessing - defaults' }
RBPragmaEnvironment class >> defaultName [
	^ 'Pragmas'
]

{ #category : 'api' }
RBPragmaEnvironment class >> keywords: aKeywordCollection [
	^ self
		onEnvironment: self default
		keywords: aKeywordCollection
]

{ #category : 'api' }
RBPragmaEnvironment class >> onEnvironment: anEnvironment keywords: aKeywordCollection [
	^ (self onEnvironment: anEnvironment)
		keywords: aKeywordCollection;
		yourself
]

{ #category : 'comparing' }
RBPragmaEnvironment >> = anObject [
	"Answer whether the receiver and anObject represent the same object."

	self == anObject ifTrue: [ ^ true ].
	self class = anObject class ifFalse: [ ^ false ].
	^ environment = anObject environment and: [
			  keywords = anObject basisObjects and: [
				  condition = anObject condition ] ]
]

{ #category : 'adding' }
RBPragmaEnvironment >> addKeyword: aSymbol [
	keywords add: aSymbol
]

{ #category : 'accessing' }
RBPragmaEnvironment >> basisObjects [
	^ keywords
]

{ #category : 'accessing' }
RBPragmaEnvironment >> condition [

	^ condition
]

{ #category : 'initialization' }
RBPragmaEnvironment >> condition: aBlock [
	condition := aBlock
]

{ #category : 'private' }
RBPragmaEnvironment >> defaultLabel [
	| stream |
	stream := String new writeStream.
	keywords do: [ :each | stream nextPut: $<; nextPutAll: each; nextPut: $>; nextPut: $ ].
	^ stream contents
]

{ #category : 'comparing' }
RBPragmaEnvironment >> hash [
	"Answer an integer value that is related to the identity of the receiver."

	^ keywords hash bitXor: condition hash
]

{ #category : 'testing' }
RBPragmaEnvironment >> includesClass: aClass [
	^ (environment includesClass: aClass) and: [ aClass selectors anySatisfy: [ :each | self includesSelector: each in: aClass ] ]
]

{ #category : 'testing' }
RBPragmaEnvironment >> includesPragma: aPragma [
	^ (keywords includes: aPragma selector) and: [ condition value: aPragma ]
]

{ #category : 'testing' }
RBPragmaEnvironment >> includesProtocol: aProtocol in: aClass [
	^ (environment includesProtocol: aProtocol in: aClass) and: [ (self selectorsFor: aProtocol in: aClass) notEmpty ]
]

{ #category : 'testing' }
RBPragmaEnvironment >> includesSelector: aSelector in: aClass [
	(environment includesSelector: aSelector in: aClass)
		ifFalse: [ ^ false ].
	^ (aClass compiledMethodAt: aSelector) pragmas
		anySatisfy: [ :each | self includesPragma: each ]
]

{ #category : 'initialization' }
RBPragmaEnvironment >> initialize [
	super initialize.
	keywords := IdentitySet new.
	condition := [ :pragma | true ]
]

{ #category : 'initialization' }
RBPragmaEnvironment >> keywords: aCollection [
	keywords addAll: aCollection
]

{ #category : 'copying' }
RBPragmaEnvironment >> postCopy [
	super postCopy.
	keywords := keywords copy
]

{ #category : 'storing' }
RBPragmaEnvironment >> storeOn: aStream [
	aStream nextPut: $(.
	super storeOn: aStream.
	aStream nextPutAll: ' keywords: '.
	keywords asArray storeOn: aStream.
	aStream nextPut: $)
]
